package com.weiai.wedding.entity.user;


import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.persistence.JoinColumn;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import com.google.common.collect.Lists;
import com.weiai.wedding.util.ConUtils;
import com.weiai.wedding.util.JedisKey;

/**
 * 用户表
 * @author wangweiheng
 */

@Entity
@Table(name="user")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class User implements Serializable{
	
	private static final long serialVersionUID=6011241820070393332L;
	
	/**
	 * 用户主键
	 */
	private String id;
	/**
	 * 用户名称
	 */
	private String loginName;
	/**
	 * 用户密码
	 */
	private String password;
	
	private int status;
	
	//private String parentId;
	
	private String email;
	
	private String type;
	
	private String createdBy;
	
	private Date createdTime;
	
	private String modifyBy;
	private Date modifyTime;
	private String mobile;
	private String nikeName;
	private String descpt;
	private List<String> authList = Lists.newArrayList();
	/**
	 * 权限编码串
	 */
	private String authCodeString;
	
	/**
	 * 格式化时间
	 */
	private String createdTimeStr;
	private String modifyTimeStr;
	public User(){
		
	}
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
	@Column(nullable=false,length = 50)
	public String getLoginName() {
		return loginName;
	}
	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}
	
	@Column(nullable=false,length = 50)
	public String getPassword() {
		return password;
	}
	
	public void setPassword(String password) {
		this.password = password;
	}
	
	
	@Column(nullable=true,length = 10)
	public int getStatus() {
		return status;
	}
	public void setStatus(int status) {
		this.status = status;
	}
	
	
	
//	public String getParentId() {
//		return parentId;
//	}
//	public void setParentId(String parentId) {
//		this.parentId = parentId;
//	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	
	public String getCreatedBy() {
		return createdBy;
	}
	public void setCreatedBy(String createdBy) {
		this.createdBy = createdBy;
	}
	public String getModifyBy() {
		return modifyBy;
	}
	public void setModifyBy(String modifyBy) {
		this.modifyBy = modifyBy;
	}
	@Column(nullable=false)
	@Temporal(TemporalType.TIMESTAMP)
	public Date getCreatedTime() {
		return createdTime;
	}
	public void setCreatedTime(Date createdTime) {
		this.setCreatedTimeStr(ConUtils.formatDate(createdTime,"yyyy-MM-dd"));
		this.createdTime = createdTime;
	}
	@Column(nullable=false)
	@Temporal(TemporalType.TIMESTAMP)
	public Date getModifyTime() {
		return modifyTime;
	}
	public void setModifyTime(Date modifyTime) {
		this.setModifyTimeStr(ConUtils.formatDate(modifyTime,"yyyy-MM-dd"));
		this.modifyTime = modifyTime;
	}
	
	public String getMobile() {
		return mobile;
	}
	public void setMobile(String mobile) {
		this.mobile = mobile;
	}
	public String getNikeName() {
		return nikeName;
	}
	public void setNikeName(String nikeName) {
		this.nikeName = nikeName;
	}
	public String getDescpt() {
		return descpt;
	}
	public void setDescpt(String descpt) {
		this.descpt = descpt;
	}
	

	@ElementCollection
	@CollectionTable(name = "USER_AUTH", joinColumns = {@JoinColumn(name = "USER_ID") })
	@Column(name = "AUTH_CODE")
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	public List<String> getAuthList() {
		return authList;
	}

	
	public void setAuthList(List<String> authList) {
		this.authList = authList;
	}
	
	@Transient
	public String getAuthCodeString() {
		return authCodeString;
	}
	public void setAuthCodeString(String authCodeString) {
		this.authCodeString = authCodeString;
	}
	@Transient
	public String getCreatedTimeStr() {
		return createdTimeStr;
	}
	public void setCreatedTimeStr(String createdTimeStr) {
		this.createdTimeStr = createdTimeStr;
	}
	
	@Transient
	public String getModifyTimeStr() {
		return modifyTimeStr;
	}
	public void setModifyTimeStr(String modifyTimeStr) {
		this.modifyTimeStr = modifyTimeStr;
	}
	/**
	 * 如果需要，则返回redis中的key值，用来保存这个对象，以hash的形式
	 */
	@Override
	public String toString() {
		return JedisKey.PALTFORM_HASH_USER_ID_KEY+this.getId();
	}
	
	
}
